import React, {Component} from "react";
import About from "./pages/About";
import Home from "./pages/Home";

import MyNavLink from "./components/MyNavLink";
import {Route, Switch,Redirect} from "react-router-dom";


export default class App extends Component {

    render() {
        return (
            <div>
                <div className="row">
                    <div className="col-xs-offset-2 col-xs-8">
                        <div className="page-header"><h2>React Router Demo</h2></div>
                    </div>
                </div>
                <div className="row">
                    <div className="col-xs-2 col-xs-offset-2">
                        <div className="list-group">
                            <MyNavLink to="/about" className="list-group-item" children="About"></MyNavLink>
                            <MyNavLink to="/home" className="list-group-item" children="Home"></MyNavLink>
                        </div>
                    </div>
                    <Switch>
                        <Route path="/about" component={About}/>
                        <Route path="/home" component={Home}/>
                        {/*
                        Redirect的使用
                          1.一般写在所有路由注册的最下方，当所有路由都无法匹配时，跳转到Redirect指定的路由
                          2.具体编码:
                          <Switch>
                          <Route path="/about" component={About}/>
                          <Route path="/home" component={Home}/>
                          <Redirect to="/about"/>
                          </Switch>
                        */}

                        <Redirect to="/about"></Redirect>
                    </Switch>
                </div>
            </div>


        )
    }
}